package week4.day25;

/**
 * @Author fengzihao
 * @Date 2024-05-09 19:37
 */
public class DownloadByThread {
    public static void main(String[] args) {
        Thread thread1 = new DownloadThread();
        Thread thread2 = new DownloadThread();
        Thread thread3 = new DownloadThread();
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class DownloadThread extends Thread{
    static int num = 100;
    static int inNum = 0;
    static final Object OBJECT = new Object();

    @Override
    public void run() {
        synchronized (OBJECT){
            while(num>0){
                inNum++;
                num--;
                System.out.println("本次下载已完成，已经下载了"+ inNum +"M");
            }
        }
        System.out.println("已下载完毕");
    }
}
